import pymysql
import csv

def from_mysql_get_all_info():
    conn = pymysql.connect(
        host='192.168.11.23',
        port=30306,
        user='root',
        db='bank',
        password='123456',
        charset='utf8mb4')
    cursor = conn.cursor()
    #sql = 'select * from bankinfo where longitude = "";
    sql = 'select * from bankinfo;'
    #sql = 'SELECT * FROM filter;'
    cursor.execute(sql.encode('utf-8'))
    data = cursor.fetchall()
    conn.close()
    return data


def write_csv():
    num = 0
    data = from_mysql_get_all_info()
    filename = 'bankinfo.csv'
    with open(filename, mode='w', newline='', encoding='utf-8') as f:
        write = csv.writer(f, dialect='excel')
        for item in data:
            write.writerow(item)
            num = num + 1
            print(num, item)

write_csv()